/*
 * Sesame Inc.
 * Copyright (c) 2009 All Rights Reserved.
 */
package com.sesame.serviceimpl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.sesame.domain.Ask;
import com.sesame.service.PageService;
import com.sesame.service.UserService;
import com.sesame.toolkit.Page;

/**
 * @author shubeta
 * 
 */
public class PageServiceImpl implements PageService {

    private Integer currentPage;
    private Page page;

    public Page paging(HttpServletRequest request, String page, Integer pageSize) {

        if (page == null) {
            currentPage = 1;
            this.page = new Page(currentPage, pageSize);
            request.getSession().setAttribute("currentPage", currentPage);
        } else {
            currentPage = Integer.parseInt(page);
            this.page = new Page(currentPage, pageSize);
            request.getSession().setAttribute("currentPage", currentPage);
        }

        return this.page;
    }

    public Page paging(HttpServletRequest request, String page) {

        if (page == null) {
            currentPage = 1;
            this.page = new Page(currentPage);
            request.getSession().setAttribute("currentPage", currentPage);
        } else {
            currentPage = Integer.parseInt(page);
            this.page = new Page(currentPage);
            request.getSession().setAttribute("currentPage", currentPage);
        }

        return this.page;
    }
}